package cvi.com.reader.adapter;

import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.orhanobut.hawk.Hawk;

import java.util.HashMap;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cvi.com.reader.R;
import cvi.com.reader.bean.constant;

/**
 * Created by 梅涛 on 2020/11/20.
 */

public class SelectPictureAdapter extends BaseAdapter {
    private Context context;
    private List<String> selectPictureBeanList;
    private LayoutInflater mInflater;
    private ViewHolder viHolder;
    private int selectorPosition=-1;
    public List<String> getSelectPictureBeanList() {
        return selectPictureBeanList;
    }

    public void setSelectPictureBeanList(List<String> selectPictureBeanList) {
        this.selectPictureBeanList = selectPictureBeanList;
    }

    public SelectPictureAdapter(Context context, List<String> selectPictureBeanList) {
        this.context = context;
        this.selectPictureBeanList = selectPictureBeanList;
        mInflater = LayoutInflater.from(context);
    }



    @Override
    public int getCount() {
        return selectPictureBeanList.size();
    }

    @Override
    public Object getItem(int i) {
        return selectPictureBeanList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        final int mPosition = i;
        if (view == null) {
            view = mInflater.inflate(
                    R.layout.item_avatar, null);
            viHolder = new ViewHolder(view);
            view.setTag(viHolder);
        } else {
            viHolder = (ViewHolder) view.getTag();
        }

     /*   String strUrl = null;
        if (Hawk.contains("ip")) {
            strUrl = Hawk.get("ip");
        }
        if (strUrl != null) {

        }*/
        ImageLoader.getInstance().displayImage("http://" + constant.URL + selectPictureBeanList.get(i), viHolder.avatar);
        if (selectorPosition == i) {
            viHolder.checkBox.setChecked(true);
        } else {
            viHolder.checkBox.setChecked(false);
        }

        return view;
    }
    public void changeState(int pos) {
        selectorPosition = pos;
        notifyDataSetChanged();

    }
    static class ViewHolder {
        @BindView(R.id.avatar)
        ImageView avatar;
        @BindView(R.id.check_box)
        CheckBox checkBox;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
